package com.jxwifi.cloud.quickclean.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import java.util.List;

/**
 * Created by wkk on 2018/1/12.
 */

public class TabPageAdapter extends FragmentPagerAdapter {
    private List<Fragment> fragments;
    private String[] tabNames;


    public TabPageAdapter(FragmentManager fm, List<Fragment> fragments,String[] tabNames) {
        super(fm);
        this.fragments = fragments;
        this.tabNames=tabNames;
    }

    @Override
    public Fragment getItem(int position) {
        return fragments.get(position);
    }

    @Override
    public long getItemId(int position) {
        return fragments.get(position).hashCode();  //这个方法处理Fragment数据传递的时候一直是第一次的数据问题，需要重写这个方法
    }

    @Override
    public int getCount() {
        return fragments.size();//fragments.size() Integer.MAX_VALUE
    }
    //重写getPageTitle方法
    @Override
    public CharSequence getPageTitle(int position) {
        //返回tab选项的名字
        return tabNames[position];
    }
}
